import java.util.Scanner;

public class funcation {
    //交换两个整型变量
    //传引用类型参数
    public static void swap(int[] arr) {
        int tmp = arr[0];
        arr[0] = arr[1];
        arr[1] = tmp;
    }


    public static void swap(int x, int y) {//err
        int tmp = x;
        x = y;
        y = tmp;
    }
    public static void main(String[] args) {
        int[] arr = {10,20};
        swap(arr);
        System.out.println("arr[0] = "+arr[0]+"arr[1] = "+arr[1]);

        //法1
        int a = 10;
        int b = 20;
//        int tmp = b;
//        b = a;
//        a = tmp;
        //法2（不溢出的情况下）
//        a = a+b;
//        b = a-b;//b = a
//        a = a-b;//a = b
//        System.out.println(a);
//        System.out.println(b);
        //法3（位运算）
//        a = a ^ b;//a ^ a = 0
//        b = a ^ b;//0 ^ a = a
//        a = a ^ b;
//        System.out.println(a);
//        System.out.println(b);
        //法4构造方法
        swap(a,b);
        System.out.println("a = "+a+"b = "+b);

    }

    //求数的和(从1加到输入的数）
    public static int getSum(int n) {
        return n*(n+1)/2;
    }

    public static void main4(String[] args) {
        int ret = getSum(10);
        System.out.println(ret);
    }





    //求n的阶乘之和
    public static int facSum(int n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += fac(i);
        }
        return sum;
    }
    //求n的阶乘
    public static int fac(int n) {
        int num = 1;
        for (int i = 1; i <= n ; i++) {
            num *= i;
        }
        return num;
    }

    public static void main3(String[] args) {
        //调用求阶乘之和的方法
        int ret = facSum(6);
        System.out.println(ret);
    }





    //判断闰年的方法
    public static int is_leap_year(int n) {
        if(n % 4 == 0 && n %100 != 0){
            return n;
        }else if(n % 400 == 0)
        {
            return n;
        }else{
            return -1;
        }
    }
//构造加法方法
    public static int add(int x,int y){
        return x+y;
    }
    //构造打印加法结果的方法
    public static void add(int y,int x,int z) {//重载函数
        System.out.println(x + y);
    }

    public static void main2(String[] args) {
        int x = 7;
        int y = 37;
        int ret = add(x,y);
        System.out.println(ret);
    }

    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ret = is_leap_year(sc.nextInt());
        if(ret != -1)
        System.out.println(ret + "年是闰年");
    }

}

